#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Charles.chen
# createDate:2017/9/28
# Title: 文件管理
# Tip:
from app.model import FileManager
from app.toolkit import commonUtil

# 添加新的文件记录
def addNewFileRow(name="", suffix="", size=0, type="sensor"):
    insertData = {
        "name": name,
        "suffix": suffix,
        "full_name": name+"."+suffix,
        "size": size,
        "type": type
    }
    return FileManager.insert(insertData).execute()
    pass

# 根据类型获取文件列表
# type "sensor"：传感数据文件 || "iot"：iot配置文件 || "dust"：微尘配置文件

def getFileListByType(type="sensor"):
    try:
        res = FileManager.select().where(FileManager.type == type).order_by(FileManager.created_time.desc).execute()
    except Exception:
        res = None
    result = commonUtil.getFieldsFromModelCls(res, FileManager) if res is not None else None
    return result




if __name__ == '__main__':
    pass

